package com.ld.security.demo.base.service;/*
package com.ld.security.auth.server.base.service;

import com.ld.security.common.core.base.column.ListString;
import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.core.util.UuidUtil;
import com.ld.security.common.shiro.anno.PermissionKey;
import com.ld.security.auth.common.sys.entity.SysPerEntity;
import com.ld.security.auth.common.sys.service.ISysPerService;
import com.ld.security.common.tomcat.base.api.SuperApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;


@Component
public class RbacDataService {

    @Autowired(required = false)
    private List<SuperApi> apiList;

    @Autowired(required = false)
    ISysPerService permissionService;



    public void initPermissionData(){
        for (SuperApi superApi : apiList) {
            initClassPermission(superApi.getClass());
        }
    }



    private void initClassPermission(Class clazz){
        HashMap<String,SysPerEntity> map = new HashMap<>(300);

        PermissionKey parentKey =  AnnotationUtils.findAnnotation(clazz,PermissionKey.class);
        SysPerEntity parent = null;
        if(parentKey != null){
            String label=parentKey.label(),value=parentKey.value();

            parent = new SysPerEntity();
            if(StringUtil.isNull(label)){
                Api api =   AnnotationUtils.findAnnotation(clazz,Api.class);
                if(api != null){
                    label = api.tags()[0];
                }
            }
            if(StringUtil.isNull(value)){
                RequestMapping requestMapping =   AnnotationUtils.findAnnotation(clazz,RequestMapping.class);
                if(requestMapping != null){
                    value = requestMapping.value()[0];
                }
            }

            parent.setLabel(label);
            parent.setCode(value);
            parent.setParentPath(new ListString("0"));
            UuidUtil.initIdKey(parent);

            map.put(parent.getId(),parent);
        }

        for (Method method : clazz.getMethods()) {
           PermissionKey permissionKey =  AnnotationUtils.findAnnotation(method,PermissionKey.class);
           if(permissionKey == null){
               continue;
           }
           String label = permissionKey.label();
           String value = permissionKey.value();
           if(parentKey != null){
               value =parentKey.value() + permissionKey.value();
           }
           if(StringUtil.isNull(label)){
               ApiOperation annotation =  AnnotationUtils.findAnnotation(method,ApiOperation.class);
               if(annotation != null){
                   label=annotation.value();
               }
           }
           if(StringUtil.isNull(value)){
               RequestMapping annotation =  AnnotationUtils.findAnnotation(method,RequestMapping.class);
               if(annotation != null){
                   value= annotation.value()[0];
               }
           }
            SysPerEntity permission =  new SysPerEntity();
           if(parent != null){
               permission.setParentPath(new ListString("0",parent.getId()));
               value=parent.getCode()+value;
           }
           permission.setLabel(label);
           permission.setCode(value);
           UuidUtil.initIdKey(permission);
            map.put(permission.getId(),permission);
        }


        for (String key : map.keySet()) {
            permissionService.save(map.get(key));
        }



    }
}
*/
